#include "ComponentPosition.h"

#include "Ogre.h"

#include "ComponentRenderable.h"

ComponentPosition::ComponentPosition(ComponentManager* _parent, ComponentArguments _args):
Component(_parent, _args)
{
    //ctor

/*
    if (_args.hasArgument("position"))
    {
       setPosition( _args.getArgument<Ogre::Vector3>("position"));
    }
*/

}

ComponentPosition::~ComponentPosition()
{
    //dtor
}



/** @brief registerNewComponent
  *
  * @todo: document this function
  */
void ComponentPosition::registerNewComponent(std::string _newComponentName)
{

}

/** @brief update
  *
  * @todo: document this function
  */
void ComponentPosition::update(double timeSinceLastFrame)
{

}

/** @brief loadFromXML
  *
  * @todo: document this function
  */
void ComponentPosition::loadFromXML(TiXmlElement* parentElement)
{

}

/** @brief saveToXML
  *
  * @todo: document this function
  */
void ComponentPosition::saveToXML(TiXmlElement* parentElement)
{
TiXmlElement* element = new TiXmlElement("position");
parentElement->LinkEndChild(element);

Ogre::Vector3 pos = m_position;

element->SetDoubleAttribute("x", pos.x);
element->SetDoubleAttribute("y", pos.y);
element->SetDoubleAttribute("z", pos.z);
}

/** @brief destroy
  *
  * @todo: document this function
  */
void ComponentPosition::destroy()
{

}

/** @brief initialise
  *
  * @todo: document this function
  */
void ComponentPosition::initialize()
{

}


/** @brief setPosition
  *
  * @todo: document this function
  */
void ComponentPosition::setPosition(Ogre::Vector3 _pos)
{
m_position = _pos;

if (m_parent->hasComponent("Renderable"))
{
    ((ComponentRenderable*)m_parent->getComponent("Renderable"))->getNode()->setPosition(m_position);
}

}

/** @brief getPosition
  *
  * @todo: document this function
  */
Ogre::Vector3 ComponentPosition::getPosition()
{
return m_position;
}

